package message.test;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

/**
 * .
 *
 * @author sunhao(sunhao.java@gmail.com)
 * @version V1.0, 16/1/14 下午9:47
 */
@Component
@CacheConfig(cacheNames = "user")
public class CacheDemo {

    @CachePut(key = "'user_' + #demo.pkId")
    public Demo save(Demo demo) {
        System.out.println("save into db!");
        return demo;
    }

    @Cacheable(key = "'user_' + #id")
    public Demo load(Long id) {
        System.out.println("load from db!");
        return new Demo(2L, "user2");
    }
}
